﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TDT.Land.Entity;
using TDT.Land.Utilities;
using TDT.Land.BusinessLogic;
using TDT.Land.Models;

namespace TDT.Land.Web.Controllers
{
    public class CatLandController : BaseController
    {
        //
        // GET: /Admin/
        [CustomAuthorize(Roles = "3")]
        public ActionResult Index()
        {
            List<Cat_LandModel> lstCatLand = AdminRepo.Instance.GetCatLands();
            ViewBag.lstCatLand = lstCatLand;
            return PartialView("_CatLandList", new Cat_LandModel());
            //return View(catLands);
        }

       
        #region Cat_Land
        
        [CustomAuthorize(Roles = "3")]
        public ActionResult CatLandList()
        {
            List<Cat_LandModel> lstCatLand = AdminRepo.Instance.GetCatLands();
            ViewBag.lstCatLand = lstCatLand;
            return PartialView(ScreenName._CatLandList, new Cat_LandModel());
        }
        
        [CustomAuthorize(Roles = "3")]
        public ActionResult openEdit(string id)
        {
            Guid CatLandId = id != string.Empty ? Guid.Parse(id) : Guid.Empty;

            Cat_Land CatLandInfo = AdminRepo.Instance.GetCatLandById(CatLandId);
            ViewBag.select_CategoryType = Commons.ConvertToSelectListItems(typeof(CategoryType));
            return PartialView("CatLand_Edit", CatLandInfo);
        }
        
        [CustomAuthorize(Roles = "3")]
        public ActionResult GetCatLand(int NumPage, int NumRow)
        {
            List<Cat_LandModel> lstCatLand = AdminRepo.Instance.GetCatLands(NumPage, NumRow);
            return PartialView("UC_CatLand_List", lstCatLand);
        }
        
        [CustomAuthorize(Roles = "3")]
        public ActionResult CatLandAction(Cat_Land model)
        {
            bool result = false;
            if (model.ID == null || model.ID == Guid.Empty) // Tạo mới
            {
                model.ID = Guid.NewGuid();
                result = AdminRepo.Instance.CreateCatLand(model, UserName);
            }
            else //Chinh sua
            {
                result = AdminRepo.Instance.UpdateCatLand(model, UserName);
            }
            return Content(result.ToString());
        }

        [CustomAuthorize(Roles = "3")]
        public ActionResult CatLandDelete(Cat_Land model)
        {
            bool result = false;
            if (model.ID != null || model.ID != Guid.Empty) // Tạo mới
            {
                result = AdminRepo.Instance.DeleteCatLand(model, UserName);
            }
            return Content(result.ToString());
        }
        

        #endregion

    }
}
